﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Class NetSerializer
   </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="Class NetSerializer
   ">
    <meta name="generator" content="docfx 2.58.5.0">
    
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" href="../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../styles/docfx.css">
    <link rel="stylesheet" href="../styles/main.css">
    <meta property="docfx:navrel" content="../toc.html">
    <meta property="docfx:tocrel" content="toc.html">
    
    
    
  </head>
  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>
        
        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              
              <a class="navbar-brand" href="../index.html">
                <img id="logo" class="svg" src="../logo.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
            </div>
          </div>
        </nav>
        
        <div class="subnav navbar navbar-default">
          <div class="container hide-when-search" id="breadcrumb">
            <ul class="breadcrumb">
              <li></li>
            </ul>
          </div>
        </div>
      </header>
      <div role="main" class="container body-content hide-when-search">
        
        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div id="sidetoc"></div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="LiteNetLib.Utils.NetSerializer">
  
  
  <h1 id="LiteNetLib_Utils_NetSerializer" data-uid="LiteNetLib.Utils.NetSerializer" class="text-break">Class NetSerializer
  </h1>
  <div class="markdown level0 summary"></div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><span class="xref">System.Object</span></div>
    <div class="level1"><span class="xref">NetSerializer</span></div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="LiteNetLib.Utils.html">LiteNetLib.Utils</a></h6>
  <h6><strong>Assembly</strong>: LiteNetLib.dll</h6>
  <h5 id="LiteNetLib_Utils_NetSerializer_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public class NetSerializer</code></pre>
  </div>
  <h3 id="constructors">Constructors
  </h3>
  
  
  <a id="LiteNetLib_Utils_NetSerializer__ctor_" data-uid="LiteNetLib.Utils.NetSerializer.#ctor*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer__ctor" data-uid="LiteNetLib.Utils.NetSerializer.#ctor">NetSerializer()</h4>
  <div class="markdown level1 summary"></div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public NetSerializer()</code></pre>
  </div>
  
  
  <a id="LiteNetLib_Utils_NetSerializer__ctor_" data-uid="LiteNetLib.Utils.NetSerializer.#ctor*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer__ctor_System_Int32_" data-uid="LiteNetLib.Utils.NetSerializer.#ctor(System.Int32)">NetSerializer(Int32)</h4>
  <div class="markdown level1 summary"></div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public NetSerializer(int maxStringLength)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">System.Int32</span></td>
        <td><span class="parametername">maxStringLength</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h3 id="methods">Methods
  </h3>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_Deserialize_" data-uid="LiteNetLib.Utils.NetSerializer.Deserialize*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_Deserialize__1_LiteNetLib_Utils_NetDataReader_" data-uid="LiteNetLib.Utils.NetSerializer.Deserialize``1(LiteNetLib.Utils.NetDataReader)">Deserialize&lt;T&gt;(NetDataReader)</h4>
  <div class="markdown level1 summary"><p>Reads packet with known type</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public T Deserialize&lt;T&gt;(NetDataReader reader)
    where T : class, new()</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.NetDataReader.html">NetDataReader</a></td>
        <td><span class="parametername">reader</span></td>
        <td><p>NetDataReader with packet</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">T</span></td>
        <td><p>Returns packet if packet in reader is matched type</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h5 class="exceptions">Exceptions</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Condition</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.InvalidTypeException.html">InvalidTypeException</a></td>
        <td><p><code data-dev-comment-type="typeparamref" class="typeparamref">T</code>&apos;s fields are not supported, or it has no fields</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_Deserialize_" data-uid="LiteNetLib.Utils.NetSerializer.Deserialize*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_Deserialize__1_LiteNetLib_Utils_NetDataReader___0_" data-uid="LiteNetLib.Utils.NetSerializer.Deserialize``1(LiteNetLib.Utils.NetDataReader,``0)">Deserialize&lt;T&gt;(NetDataReader, T)</h4>
  <div class="markdown level1 summary"><p>Reads packet with known type (non alloc variant)</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public bool Deserialize&lt;T&gt;(NetDataReader reader, T target)
    where T : class, new()</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.NetDataReader.html">NetDataReader</a></td>
        <td><span class="parametername">reader</span></td>
        <td><p>NetDataReader with packet</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">T</span></td>
        <td><span class="parametername">target</span></td>
        <td><p>Deserialization target</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">System.Boolean</span></td>
        <td><p>Returns true if packet in reader is matched type</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h5 class="exceptions">Exceptions</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Condition</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.InvalidTypeException.html">InvalidTypeException</a></td>
        <td><p><code data-dev-comment-type="typeparamref" class="typeparamref">T</code>&apos;s fields are not supported, or it has no fields</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_Register_" data-uid="LiteNetLib.Utils.NetSerializer.Register*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_Register__1" data-uid="LiteNetLib.Utils.NetSerializer.Register``1">Register&lt;T&gt;()</h4>
  <div class="markdown level1 summary"></div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void Register&lt;T&gt;()</code></pre>
  </div>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h5 class="exceptions">Exceptions</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Condition</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.InvalidTypeException.html">InvalidTypeException</a></td>
        <td><p><code data-dev-comment-type="typeparamref" class="typeparamref">T</code>&apos;s fields are not supported, or it has no fields</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_RegisterNestedType_" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_RegisterNestedType__1" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType``1">RegisterNestedType&lt;T&gt;()</h4>
  <div class="markdown level1 summary"><p>Register custom property type</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void RegisterNestedType&lt;T&gt;()
    where T : struct, INetSerializable</code></pre>
  </div>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td><p>INetSerializable structure</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_RegisterNestedType_" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_RegisterNestedType__1_System_Action_LiteNetLib_Utils_NetDataWriter___0__System_Func_LiteNetLib_Utils_NetDataReader___0__" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType``1(System.Action{LiteNetLib.Utils.NetDataWriter,``0},System.Func{LiteNetLib.Utils.NetDataReader,``0})">RegisterNestedType&lt;T&gt;(Action&lt;NetDataWriter, T&gt;, Func&lt;NetDataReader, T&gt;)</h4>
  <div class="markdown level1 summary"><p>Register custom property type</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void RegisterNestedType&lt;T&gt;(Action&lt;NetDataWriter, T&gt; writer, Func&lt;NetDataReader, T&gt; reader)</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">System.Action</span>&lt;<a class="xref" href="LiteNetLib.Utils.NetDataWriter.html">NetDataWriter</a>, T&gt;</td>
        <td><span class="parametername">writer</span></td>
        <td><p>custom type writer</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">System.Func</span>&lt;<a class="xref" href="LiteNetLib.Utils.NetDataReader.html">NetDataReader</a>, T&gt;</td>
        <td><span class="parametername">reader</span></td>
        <td><p>custom type reader</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td><p>Any packet</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_RegisterNestedType_" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_RegisterNestedType__1_System_Func___0__" data-uid="LiteNetLib.Utils.NetSerializer.RegisterNestedType``1(System.Func{``0})">RegisterNestedType&lt;T&gt;(Func&lt;T&gt;)</h4>
  <div class="markdown level1 summary"><p>Register custom property type</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void RegisterNestedType&lt;T&gt;(Func&lt;T&gt; constructor)
    where T : class, INetSerializable</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">System.Func</span>&lt;T&gt;</td>
        <td><span class="parametername">constructor</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td><p>INetSerializable class</p>
</td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_Serialize_" data-uid="LiteNetLib.Utils.NetSerializer.Serialize*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_Serialize__1___0_" data-uid="LiteNetLib.Utils.NetSerializer.Serialize``1(``0)">Serialize&lt;T&gt;(T)</h4>
  <div class="markdown level1 summary"><p>Serialize object to byte array</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public byte[] Serialize&lt;T&gt;(T obj)
    where T : class, new()</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">T</span></td>
        <td><span class="parametername">obj</span></td>
        <td><p>Object to serialize</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="returns">Returns</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="xref">System.Byte</span>[]</td>
        <td><p>byte array with serialized data</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  
  
  <a id="LiteNetLib_Utils_NetSerializer_Serialize_" data-uid="LiteNetLib.Utils.NetSerializer.Serialize*"></a>
  <h4 id="LiteNetLib_Utils_NetSerializer_Serialize__1_LiteNetLib_Utils_NetDataWriter___0_" data-uid="LiteNetLib.Utils.NetSerializer.Serialize``1(LiteNetLib.Utils.NetDataWriter,``0)">Serialize&lt;T&gt;(NetDataWriter, T)</h4>
  <div class="markdown level1 summary"><p>Serialize object to NetDataWriter (fast)</p>
</div>
  <div class="markdown level1 conceptual"></div>
  <h5 class="decalaration">Declaration</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void Serialize&lt;T&gt;(NetDataWriter writer, T obj)
    where T : class, new()</code></pre>
  </div>
  <h5 class="parameters">Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.NetDataWriter.html">NetDataWriter</a></td>
        <td><span class="parametername">writer</span></td>
        <td><p>Serialization target NetDataWriter</p>
</td>
      </tr>
      <tr>
        <td><span class="xref">T</span></td>
        <td><span class="parametername">obj</span></td>
        <td><p>Object to serialize</p>
</td>
      </tr>
    </tbody>
  </table>
  <h5 class="typeParameters">Type Parameters</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="parametername">T</span></td>
        <td></td>
      </tr>
    </tbody>
  </table>
  <h5 class="exceptions">Exceptions</h5>
  <table class="table table-bordered table-striped table-condensed">
    <thead>
      <tr>
        <th>Type</th>
        <th>Condition</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><a class="xref" href="LiteNetLib.Utils.InvalidTypeException.html">InvalidTypeException</a></td>
        <td><p><code data-dev-comment-type="typeparamref" class="typeparamref">T</code>&apos;s fields are not supported, or it has no fields</p>
</td>
      </tr>
    </tbody>
  </table>
</article>
          </div>
          
          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <div class="contribution">
                <ul class="nav">
                </ul>
              </div>
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
                <h5>In This Article</h5>
                <div></div>
              </nav>
            </div>
          </div>
        </div>
      </div>
      
      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
            
            <span>Generated by <strong>DocFX</strong></span>
          </div>
        </div>
      </footer>
    </div>
    
    <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
    <script type="text/javascript" src="../styles/docfx.js"></script>
    <script type="text/javascript" src="../styles/main.js"></script>
  </body>
</html>
